package com.rdk.action;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; 
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.rdk.constant.Forward;
import com.rdk.constant.StrConstant;
import com.rdk.entity.User;
import com.rdk.service.UserInfoService;
import com.rdk.utils.CommonUtil;

@Controller
public class LoginAction extends BaseAction {
	
	@Autowired
	private UserInfoService userInfoService;
	
	@RequestMapping(value="login")
	public String toLogin(HttpServletRequest  request, 	ModelMap map){
		return Forward.ActionPage.LOGIN;
	}
	
	@RequestMapping(value="vaildUser")
	public String vaildUser(HttpServletRequest request, ModelMap map){
		String name = CommonUtil.getRequest(request, "userName");
		String password = CommonUtil.getRequest(request, "password");
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("name", name);
		paramMap.put("password", password);
		User user = userInfoService.getUserInfo(paramMap);
		
		map.put("user", user);
		map.put(StrConstant.PAGE, Forward.ActionPage.INDEX);
		return Forward.ActionPage.PUBLIC;
	}

}
